package com.ants.logic.visualize.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ants.logic.visualize.dao.TblStorageMapper;
import com.ants.logic.visualize.dto.DecreaseStorageDto;
import com.ants.logic.visualize.entity.TblStorage;
import com.ants.logic.visualize.service.TblStorageService;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.springframework.stereotype.Service;

/**
 * @author 蚂蚁会花呗
 * @date 2021/9/9 16:03
 */
@Service
public class TblStorageServiceImpl extends ServiceImpl<TblStorageMapper, TblStorage> implements TblStorageService {


    static Log log = LogFactory.getLog(TblStorageServiceImpl.class);

    @Override
    public void decreaseStorage(DecreaseStorageDto decreaseStorageDto) {
        TblStorage tblStorage = this.getById(decreaseStorageDto.getProductId());
        log.info("开始操作库存");
        //设置已使用库存
        tblStorage.setUsed(tblStorage.getUsed() + decreaseStorageDto.getOrderCount());
        boolean flag = this.saveOrUpdate(tblStorage);
        if (flag){
            throw new RuntimeException("主动抛异常");
        }

        log.info("库存增减结束!");
    }
}
